﻿using SosForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using SosData;

namespace UOCmaker
{
    public partial class FormBuscarPlantilla : FormBase
    {

        #region " Constructores "

        /// <summary>
        /// constructor
        /// </summary>
        public FormBuscarPlantilla()
        {
            InitializeComponent();
        }


        public FormBuscarPlantilla(Type entidad)
        {
            InitializeComponent();
        }
        #endregion


        #region " Metodos "


        private void Buscar()
        {

            //var plantContenidos = SosBL.DataBL.Filter<PlantillaContenido>(typeof(PlantillaContenido), this.cmbCampos.Text, txtCriteria.Text, cmbOperadores.Text);

            var plantContenidos = SosBL.DataBL.Filter(typeof(PlantillaContenido), this.cmbCampos.Text, txtCriteria.Text, cmbOperadores.Text);

            bindingSource.DataSource = plantContenidos.Cast<PlantillaContenido>().ToList();

        }
        #endregion

        private void FormBuscarPlantilla_Load(object sender, EventArgs e)
        {
            foreach (string item in SosBL.DataBL.GetProperties(typeof(PlantillaContenido)))
            {
                this.cmbCampos.Items.Add(item.ToString());
            }
        }

        private void butBuscar_Click(object sender, EventArgs e)
        {
            Buscar();
        }

        private void butCancelar_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public int idSeleccionado = -1;
        private void butSeleccionar_Click(object sender, EventArgs e)
        {
            idSeleccionado = ((EntityBase)bindingSource.Current).Id;
            this.Close();
        }
    }
}
